package com.transcasafe.eanpay.example.pay;

import com.alibaba.fastjson.JSONObject;
import com.transcasafe.eanpay.core.config.EanPayConfig;
import com.transcasafe.eanpay.core.service.EanPayCardService;
import com.transcasafe.eanpay.core.service.model.OrderInfoInRequest;
import com.transcasafe.eanpay.core.service.model.PaymentsPayRequest;
import com.transcasafe.eanpay.core.service.model.PaymentsPayResponse;
import com.transcasafe.eanpay.core.service.model.ProductInfoInRequest;
import com.transcasafe.eanpay.core.util.NonceUtil;
import com.transcasafe.eanpay.example.MchConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * 代收订单创建-收银台模式
 */
public class EanPayCheckoutModePaymentsExample {
    public static void main(String[] args) {
        EanPayConfig config = new EanPayConfig.Builder().mchNo(MchConfig.mchNo).mchKey(MchConfig.mchKey).build();
        EanPayCardService service = new EanPayCardService.Builder().config(config).hostname(MchConfig.hostname).build();
        PaymentsPayRequest request = new PaymentsPayRequest();
        request.setNotifyUrl("https://card-api.ean-pay.com/v1/card-pay/cybersource-payments/notify-test");
        String price = "1000";

        // 订单信息
        OrderInfoInRequest orderInfo = new OrderInfoInRequest();
        orderInfo.setAmount(price);
        orderInfo.setCurrency("RUB");
        orderInfo.setMchOrderNo(NonceUtil.createNonce(16));
        orderInfo.setPayModel("CARDPAYMENT");

        request.setOrderInfo(orderInfo);

        PaymentsPayResponse response = service.pay(request);
        System.out.println(JSONObject.toJSONString(response));
    }
}
